<template>
	<view class="container">
		<button @click="wxlogin">获取openid</button>
		<button @click="getOrder">测试支付</button>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				href: 'https://uniapp.dcloud.io/component/README?id=uniui'
			}
		},
		created() {
			// this.wxlogin()
			// this.getOrder()
		},
		data() {
			return {
				openid: ''
			}
		},
		methods: {
			getOrder() {
				uni.request({
					// 111.67.198.176
					url: "http://localhost:8000/pay/placeOrder",
					method: 'POST',
					data: {
						openid: this.openid,
						total: 1,
						description: "小企鹅",
						out_trade_no: "100143578fd"
					},
					success(results) {

						if (results.data.code == 200) {

							const {
								appid,
								nonceStr,
								package: pkg,
								timeStamp,
								signType,
								paySign
							} = results.data.data

							uni.requestPayment({
								timeStamp,
								nonceStr,
								package: pkg,
								signType,
								paySign,
								success(res) {
									console.log(res, 'res66666');
								},
								fail(err) {
									console.log(err, 'err44444');
								}
							})
						}
					}
				})
			},
			wxlogin() {
				let that = this
				uni.login({
					success(res) {
						console.log(res, 'ressssss');
						if (res.code) {
							uni.request({
								url: "https://api.weixin.qq.com/sns/jscode2session",
								method: 'GET',
								data: {
									appid: "wxe5f62bc262ee9106",
									secret: "70fa451aaef41134568ca23551dea91f",
									js_code: res.code,
									grant_type: "authorization_code"
								},
								success(result) {
									if (result.data.openid) {
										that.openid = result.data.openid
										console.log(that.openid, 'openid============');
									}
								}
							})
						}
					}
				})
			}
		}
	}
</script>

<style>
	.container {
		padding: 20px;
		font-size: 14px;
		line-height: 24px;
	}
</style>